class Solution {
    public int maxProduct(int[] nums) {
        int maxF = 1, minF = 1, ans = nums[0];
        for (int num : nums) {
            int mx = maxF, mn = minF;
            maxF = Math.max(mx * num, Math.max(mn * num, num));
            minF = Math.min(mx * num, Math.min(mn * num, num));
            ans = Math.max(ans, maxF);
        }
        return ans;
    }
}